import Mock from 'mockjs';

// 生成报告列表数据
Mock.mock(/\/api\/v1\/report\/list/, 'get', (options: { url: string; }) => {
  const params = new URLSearchParams(options.url.split('?')[1]);
  const page = parseInt(params.get('page') || '1');
  const pageSize = parseInt(params.get('pageSize') || '20');

  return {
    code: 200,
    data: {
      total: 100,
      list: Mock.mock({
        [`list|${pageSize}`]: [{
          'reportId': '@guid',
          'title': '@ctitle(10, 30)',
          'type|1': ['industry', 'phase', 'custom'],
          'status|1': ['draft', 'published', 'archived'],
          'author': '@cname',
          'createTime': '@datetime',
          'updateTime': '@datetime',
          'publishTime': '@datetime',
          'summary': '@cparagraph(1, 3)',
          'tags|1-5': ['@ctitle(2, 4)'],
          'viewCount|0-1000': 0
        }]
      }).list
    },
    message: 'success'
  };
});

// 生成报告详情数据
Mock.mock(/\/api\/v1\/report\/[\w-]+$/, 'get', () => {
  return {
    code: 200,
    data: Mock.mock({
      'reportId': '@guid',
      'title': '@ctitle(10, 30)',
      'type|1': ['industry', 'phase', 'custom'],
      'status|1': ['draft', 'published', 'archived'],
      'content': {
        'sections|2-5': [{
          'title': '@ctitle(5, 10)',
          'content': '@cparagraph(10, 20)'
        }],
        'conclusion': '@cparagraph(5, 10)'
      },
      'attachments|0-3': [{
        'fileId': '@guid',
        'fileName': '@word(5,10).@pick(["pdf","doc","xlsx"])',
        'fileSize|1-10000': 1,
        'fileType|1': ['pdf', 'doc', 'xlsx']
      }],
      'references|0-5': [{
        'title': '@ctitle(5, 15)',
        'url': '@url',
        'type|1': ['web', 'book', 'paper']
      }],
      'author': '@cname',
      'createTime': '@datetime',
      'updateTime': '@datetime',
      'publishTime': '@datetime',
      'summary': '@cparagraph(1, 3)',
      'tags|1-5': ['@ctitle(2, 4)'],
      'viewCount|0-1000': 0,
      'version': '1.0.0'
    }),
    message: 'success'
  };
});

// 创建报告
Mock.mock('/api/v1/report', 'post', () => {
  return {
    code: 200,
    data: {
      reportId: Mock.Random.guid()
    },
    message: '创建成功'
  };
});

// 更新报告
Mock.mock(/\/api\/v1\/report\/[\w-]+$/, 'put', () => {
  return {
    code: 200,
    message: '更新成功'
  };
});

// 删除报告
Mock.mock(/\/api\/v1\/report\/[\w-]+$/, 'delete', () => {
  return {
    code: 200,
    message: '删除成功'
  };
});

// 导出报告
Mock.mock(/\/api\/v1\/report\/[\w-]+\/export$/, 'post', () => {
  return {
    code: 200,
    data: {
      url: Mock.Random.url()
    },
    message: 'success'
  };
});